How to get `gcc` to generate `bts` instruction for x86-64 from standard C?
Posted
by Norman Ramsey
on Stack Overflow
See other posts from Stack Overflow
or by Norman Ramsey
Published on 2010-01-11T04:07:24Z
Indexed on
2010/03/08
1:40 UTC
Read the original article
Hit count: 319
Inspired by a recent question, I'd like to know if anyone knows how to get gcc
to generate the x86-64 bts
instruction (bit test and set) on the Linux x86-64 platforms, without resorting to inline assembly or to nonstandard compiler intrinsics.
Related questions:
Why doesn't gcc do this for a simple
|=
operation were the right-hand side has exactly 1 bit set?How to get
bts
using compiler intrinsics or theasm
directive
Portability is more important to me than bts
, so I won't use and asm
directive, and if there's another solution, I prefer not to use compiler instrinsics.
EDIT: The C source language does not support atomic operations, so I'm not particularly interested in getting atomic test-and-set (even though that's the original reason for test-and-set to exist in the first place). If I want something atomic I know I have no chance of doing it with standard C source: it has to be an intrinsic, a library function, or inline assembly. (I have implemented atomic operations in compilers that support multiple threads.)
© Stack Overflow or respective owner